package org.glut.backend.controller;

/*import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;*/
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.glut.backend.domain.Performance;
import org.glut.backend.service.IPerformanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 演出表 前端控制器
 *
 * @author hjd
 * @since 2025-08-03 11:33
 */
//@Api(tags = "演出表前端控制器")
@Slf4j
@RestController
@RequestMapping("/public/maoyanmovieproject")
public class PerformanceController {

    /**
     * 根据id查询演出信息
     * @param id
     * @return
     */
    @Autowired
    IPerformanceService performanceService;

    @GetMapping("/queryPerformanceById/{id}")
    public ResponseEntity<Performance> getById(@PathVariable Integer id) {
        log.info("ID:{}",id);
        Performance performance = this.performanceService.getById(id);
        //定义http请求头
        HttpHeaders httpHeaders = new HttpHeaders();
        //添加自定义请求头
        httpHeaders.add("token", "haha");
        return new ResponseEntity<Performance>(performance, httpHeaders, HttpStatus.OK);
    }

    /**
     * 查询所有演出信息
     *
     * @return
     */
    // FunctionbarController.java
    @GetMapping("/queryAllPerformance")
    public ResponseEntity<List<Performance>> queryAllPerformance() {
        List<Performance> list = performanceService.list(); // 查询所有演出信息
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("token", "haha");
        return new ResponseEntity<>(list, httpHeaders, HttpStatus.OK);
    }


    /**
     * 根据PerformanceType查询演出信息
     * 使用LambdaQueryWrapper查询
     * @param type
     * @return
     */
    @GetMapping("/queryPerformanceByType/{type}")
        public List<Performance> getPerformanceByType(@PathVariable Integer type) {
            LambdaQueryWrapper<Performance> lambdaQuery = new LambdaQueryWrapper<>();
            // 通过实体类方法引用指定字段：Performance::getPerformanceType
            lambdaQuery.eq(Performance::getPerformanceType, type);
            return performanceService.list(lambdaQuery);
        }


    /**
     * 根据recommendType查询演出信息
     * 使用LambdaQueryWrapper查询
     * @param type
     * @return
     */
    @GetMapping("/queryRecommendByType/{type}")
    public List<Performance> getRecommendByType(@PathVariable Integer type) {
        LambdaQueryWrapper<Performance> lambdaQuery = new LambdaQueryWrapper<>();
        // 通过实体类方法引用指定字段：Performance::getPerformanceType
        lambdaQuery.eq(Performance::getRecommendType, type);
        return performanceService.list(lambdaQuery);
    }

    /**
     * 根据演出名，演出地点，演出时间 模糊查询
     * @param input
     * @return
     */
    @GetMapping("/fuzzyQueryPerformance")
    public List<Performance> fuzzyQueryPerformance(String input) {
        // Lambda 方式构建查询条件（更安全，避免字段名拼写错误）
        LambdaQueryWrapper<Performance> lambdaWrapper = new LambdaQueryWrapper<>();

        // 姓名包含 keyword（使用 User::getName 引用字段）
        lambdaWrapper.like(Performance::getPname, input)  //演出名模糊查询
                .or()  //或者
                .like(Performance::getPlocation,input)   //演出地点模糊查询
                .or()
                .like(Performance::getPtime,input);  //演出时间模糊查询
        return performanceService.list(lambdaWrapper);
    }



}

